﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Member.DbAccess
{
    internal class DbHelper
    {
        protected SqlConnection GetConnection()
        {
            return new SqlConnection("server=192.168.1.191;database=Member;uid=sa;pwd=111111;");
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public DataSet Search(string sql, params SqlParameter[] parameters)
        {
            using (var conn = GetConnection())
            using (var cmd = new SqlCommand(sql, conn))
            {
                cmd.Parameters.AddRange(parameters);
                cmd.CommandType = CommandType.Text;
                cmd.Connection.Open();
                cmd.Prepare();
                var da = new SqlDataAdapter(cmd);
                var ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
        }
    }
}
